//package com.it.water.utils.Scoket;
//
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.CommandLineRunner;
//import org.springframework.stereotype.Component;
//
//import java.io.*;
//import java.net.Socket;
//import java.sql.Connection;
//import java.sql.DriverManager;
//import java.sql.PreparedStatement;
//import java.sql.SQLException;
//
//@Component
//public class SocketConnectionRunner implements CommandLineRunner {
//
//
//    @Value("${python.server.ip}")
//    private String pythonServerIp;
//
//    @Value("${python.server.port}")
//    private int pythonServerPort;
//
//    @Override
//    public void run(String... args) {
//        try {
//            Socket socket = new Socket(pythonServerIp, pythonServerPort);//创建socket连接
//
//            // 可以在此处发送初始化消息给Python端
//            OutputStream outputStream = socket.getOutputStream();
//            outputStream.write("Hello from Java".getBytes());
//            System.out.println("消息已经发送");
//            //读取音频文件
////            FileInputStream fis = new FileInputStream("C:\\360安全浏览器下载\\3221359769\\FileRecv\\temp_audio.wav");
////            byte[] audioBuffer = new byte[2048];
////            int audioBytesRead;
////            OutputStream os = socket.getOutputStream();
////
////
////            // 将音频数据发送给Python端
////            while ((audioBytesRead = fis.read(audioBuffer)) != -1) {
////                os.write(audioBuffer, 0, audioBytesRead);
////            }
////            System.out.println("音频已经发送");
//
//
////            //接受图片数据
////            InputStream inputStream = socket.getInputStream();
////            byte[] pictureBuffer = new byte[2048];
////            int pictureBytesRead;
////            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
////
////            while ((pictureBytesRead = inputStream.read(pictureBuffer)) != -1) {
////                byteArrayOutputStream.write(pictureBuffer, 0, pictureBytesRead);
////            }
////
////            byte[] imageData = byteArrayOutputStream.toByteArray();
////
////            // 将imageData保存到数据库
////          saveImageDataToDatabase(imageData);
////
////            // 关闭流和连接
////            byteArrayOutputStream.close();
////            inputStream.close();
//
//            // 在需要时可以使用 outputStream 发送其他数据给Python端
//            // ...
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
////    private void saveImageDataToDatabase(byte[] imageData) {
////        try {
////            //连接数据库
////            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/water", "root", "1234");
////
////            // 准备数据库表
////            // （假设表格名称为images，字段为id和image_data）
////            PreparedStatement pstmt = connection.prepareStatement("INSERT INTO images (image_data) VALUES (?)");
////            pstmt.setBytes(1, imageData);
////            pstmt.executeUpdate();
////
////            // 关闭连接和资源
////           // pstmt.close();
////            //connection.close();
////
////
////    } catch (SQLException e) {
////            throw new RuntimeException(e);
////        }
////    }
//}
